using B.S.XZYData.Api.Read.Application.Command.Process;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.XZYData.Api.Read.Controllers
{
    /// <summary>
    /// 工序管理控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ProcessController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ProcessController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 工序分页查询
        /// </summary>
        /// <param name="command">查询命令</param>
        /// <returns>分页结果</returns>
        [HttpPost("query")]
        public async Task<IActionResult> QueryProcess([FromBody] QueryProcessCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 根据工序Id查询工序采集数据
        /// </summary>
        /// <param name="processId">工序ID</param>
        /// <returns>工序采集数据列表</returns>
        [HttpGet("collection-data/{processId}")]
        public async Task<IActionResult> GetProcessCollectionData(long processId)
        {
            var command = new QueryProcessCollectionDataCommand
            {
                ProcessId = processId
            };
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 获取所有工序名称（下拉）
        /// </summary>
        [HttpGet("names")]
        public async Task<IActionResult> GetAllProcessNames()
        {
            var result = await _mediator.Send(new GetAllProcessNamesCommand());
            return Ok(result);
        }

        /// <summary>
        /// 获取所有工序（完整信息）
        /// </summary>
        /// <returns>所有工序列表</returns>
        [HttpGet("all")]
        public async Task<IActionResult> GetAllProcesses()
        {
            var result = await _mediator.Send(new GetAllProcessesCommand());
            return Ok(result);
        }
    }
} 